package taliav3;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.*;

/**
 *
 *
 * Klasa realizuje rysowanie menu kontekstowe
 * do sortowania kart oraz
 * gdy wybrana/dolosowana jest karta typu
 * As
 * Joker
 * Walet
 *
 */
 
public class DrawTransformation {
    protected char Jcolor, Jrank;
    DrawTable table1;
    Card selected;
    int ind, p_index;
    char figuraPL[],kolor[], color_selected, rank_selected;
    String kolorPL[];
    public DrawTransformation(DrawTable table, int p_indexx, int c_indexx)
    {
        table1 = table;
        p_index = p_indexx;
        ind = c_indexx;
        selected = new Card(table1.players[p_index].getCard(ind));
        Jrank = '0';
        Jcolor = '0';
        color_selected='0';
        rank_selected='0';
    }
    /** Draw menu with sorting. Added Mouseadapters.*/
    protected void Sort()
    {
        int X,Y;
        for(int i=0; i<4; i++)
        {
            table1.sort[i] = new JLabel();
            final String path = "/taliav3/img/sort_"+(i+1);
            table1.sort[i].setBounds(875, 450+49*i, 125, 49);
            table1.sort[i].setIcon(new ImageIcon(getClass().getResource(path+".png")));
            table1.sort[i].addMouseListener(MouseAdapters.sortAction(path, table1));
            table1.panel.add(table1.sort[i]);
            table1.panel.moveToFront(table1.sort[i]);
        }
    }
    /** Draw colors when demand with Ace or when transforming Joker card.*/
    protected void DrawColors()
    {
        table1.BackUpDemand='0';
        table1.BackUpDemandQueue=0;
        table1.bgDC = new JLabel();
        table1.bgDC.setIcon(new ImageIcon(getClass().getResource("/taliav3/img/bg1.png")));
        table1.bgDC.setBounds(997, 520, 143, 128);
        table1.panel.add(table1.bgDC);
        table1.panel.moveToFront(table1.bgDC);
        int X,Y;
        kolor = new char[]{'H','D','S','C'};
        kolorPL = new String[]{"KIER", "KARO", "PIK", "TREFL"};
        table1.colors = new JLabel[4];
        for(int i=0; i<4; i++)
        {
            table1.colors[i] = new JLabel();
            final char color = kolor[i];
            final String path = "/taliav3/img/"+kolor[i]+"m";
            if(i>1) {   X=i%2*52;  Y=46*2;  }
            else    {   X=56*i;    Y=43;    }
            table1.colors[i].setBounds(1015+X, 500+Y, 49, 42);
            table1.colors[i].setIcon(new ImageIcon(getClass().getResource(path+"W.png")));
            table1.colors[i].addMouseListener(MouseAdapters.pickColorAction(path, color, table1, this));
            table1.panel.add(table1.colors[i]);
            table1.panel.moveToFront(table1.colors[i]);
        }
    }
    /** Draw ranks when demand with Jack or when transforming Joker card.*/
    protected void DrawRanks()
    {
        int X,Y,H,H2;
        if(selected.rank=='B')
        {
            figuraPL = new char[]{'2', '3', '4', '5', '6', '7', '8', '9', '1', 'W', 'D', 'K', 'A'};
            H=386; H2=405;
        }
        else
        {
            figuraPL = new char[]{'5', '6', '7', '8', '9', '1', 'D', 'K'};
            table1.BackUpDemand='0';
            table1.BackUpDemandQueue=0;
            H=520; H2=525;
        }
        table1.bgDR = new JLabel();
        table1.bgDR.setIcon(new ImageIcon(getClass().getResource("/taliav3/img/bg2.png")));
        table1.bgDR.setBounds(997, H2, 144, 128);
        table1.panel.add(table1.bgDR);
        table1.panel.moveToFront(table1.bgDR);
        table1.ranks = new JLabel[figuraPL.length];
        Font font1 = new Font("Century Gothic", Font.PLAIN, 30);
        for(int i=0; i<figuraPL.length; i++)
        {
            final char rank = figuraPL[i];
            Object o1 = figuraPL[i];
            String wypis = o1.toString();
            if(figuraPL[i]=='1')
                wypis+="0";
            table1.ranks[i] = new JLabel();
            double dodaj=1.0;
            if(i>4 && selected.rank!='B')
            {
                if(wypis.equals("K"))
                    dodaj = 0.8;
                X=(int) (i % 5 * 22 + i % 5 * 22 * dodaj);
                Y=36*2;
            }
            else if(i>4 && i<=8 && selected.rank=='B')   {   X=22*(i%5);    Y=36*2;    }
            else if(i>8 && selected.rank=='B')   {   X=28*(i%9);    Y=36*3;    }
            else    {   X=22*i;    Y=33;    }
            table1.ranks[i].setText(wypis);
            table1.ranks[i].setForeground(Color.white);
            int W=28+(wypis.length()-1)*22;
            table1.ranks[i].setBounds(1015+X, H+Y, W, 42);
            table1.ranks[i].setFont(font1);
            table1.ranks[i].addMouseListener(MouseAdapters.pickRankAction(wypis, rank, table1, this));
            table1.panel.add(table1.ranks[i]);
            table1.panel.moveToFront(table1.ranks[i]);
        }
    }
}
